import * as types from '../mutation-types';
import Vue from 'vue';
const state = {
	model: '',
	networkType: '',
	noticePermissionTip: true,
	permission: {
		location: false,
		notice: true
	},
	cacheSize: 0,
	newVersion: {}
}

const mutations = {
	[types.UPDATE_NETWORK_TYPE](state, networkType) {
		networkType = networkType.toUpperCase()
		if (networkType == 'UNKNOWN') {
			networkType = '';
		} else if (networkType == 'NONE') {
			networkType = '无网络';
		} else if (networkType == 'ethernet') {
			networkType = '有线网络';
		}
		state.networkType = networkType;

	},
	[types.UPDATE_DEVICE_MODEL](state, model) {
		state.model = model.replace(/[^a-zA-Z]/gi, "").replace('unknown', '');
	},
	[types.UPDATE_DEVICE_PERMISSION](state, item) {
		if (state.permission.hasOwnProperty(item.key)) {
			Vue.set(state.permission, item.key, item.value)
		}
	},
	[types.CLOSE_NOTICE_PREMISSION_TIP](state) {
		state.noticePermissionTip = false;
	},
	[types.SAVE_NEW_VERSION](state, data) {
		state.newVersion = data;
	},
	[types.INIT_CACHE_SIZE](state) {
		// #ifdef APP-PLUS
		plus.cache.calculate(size => {
			state.cacheSize = size
		});
		// #endif
		// #ifndef APP-PLUS
		state.cacheSize = 0
		// #endif
	},


}


//统一登录IM方法
const loginIM = (state) => {

}


export default {
	state,
	mutations
}
